Database management system with improved indexed accessing

ABSTRACT

A database management system (DBMS) provided with a multi-dimensional improved indexed accessing capability using keyed index searching. Individual search keys are constructed from general expression statements created in the DBMS compiler from search queries supplied to the DBMS. Each key column represents another dimension, and both ranges and IN lists can be specified in the search query and used as the predicate values in multiple columns. Missing predicate values in the search query are interpreted as a specification of the minimum and maximum values for the associated search key column. During compile time, the DBMS compiler produces general expressions to be used by the DBMS executor during run time to create the search keys. The DBMS compiler evaluates search queries by associating predicates with clusters and disjunct numbers assigned to each individual disjunct in the search query expression. The DBMS executor uses the general expression from the compiler and eliminates any conflicts among same column predicates, removes redundancies in predicate values and disjuncts and reduces the number of records to be accessed to the minimum required to complete the search query. The individual search keys are generated in the same order as the index to which the search pertains (i.e., increasing or decreasing order).

BACKGROUND OF THE INVENTION

This invention relates generally to relational database management systems, and particularly to a relational database management system with improved indexed accessing.

Most relational database management systems (DBMS) use B-Trees to allow users to perform queries on large databases or tables using appropriate commands, such as SQL (structured query language) commands. A B-Tree is an index residing in the database memory and having one or more columns, with each column representing another dimension in the index. B-Trees permit searching for records in a database using one or more keys specified by users by means of appropriate query commands. Because the keys define a subset of an entire table of records, indexed searching can eliminate the need to search through the entire table of records in order to retrieve a much smaller subset of such records pertinent to the user query.

Ideally, for most queries, indexed accessing enables the pertinent records to be accessed at minimum transactional cost (the cost being measured by an appropriate parameter, such as the equivalent number of secondary storage accesses as required to complete the query). However, many user queries presented to a DBMS using a B-Tree index structure cannot be processed using an indexed access technique. In such cases, the entire table of records must be searched, which is time consuming and relatively inefficient. In addition, the extent to which the total number of records required to be searched can be reduced is severely limited in a B-Tree index structure by virtue of the constraint that only one key column in an index can be used to specify a range of values or a specific list of values (termed an IN list). For example, consider a table T having columns (a, b, c, d, e, f, g) and a corresponding index I having columns (a, b, c, d). A user query requesting that the DBMS select all records for the predicates:

where a=10

and b between 20 and 30

and c=40

and d=50

would result in begin-end keys of the form:

begin key: a=10, b>=20

end key: a=10, b<=30

Even though the predicates specify c=40 and d=50, these two equality predicates on key columns c and d are not incorporated in the search key due to the range on b. As a result, a search in the index for records conforming to the predicates will be able to seek to the nearest (a, b) pair, but cannot position precisely on the desired (a, b, c, d) values. Stated differently, all of the c and d values in the index must be examined and compared with the specific c and d values desired. Depending on the number of records in the c and d columns, the length of time required to perform the index search (and thus the cost), at best, is greater than optimal.

Another disadvantage with existing B-Tree index structures is the constraint imposed when a key column predicate is missing (unspecified). For example, consider the predicates:

where a=10

and c=40

and d=50

The begin-end key constructed by the traditional key building method is as follows:

begin key: a=10

end key: a=10

In this case, the absence of a predicate on column b prevents the predicates on columns c and d from being used. Consequently, the index table must be searched for all values (b, c, d). A special case occurs when the missing key predicate is on the first column of a partitioning key. For example, consider the predicates:

where b=30

and c=40

and d=50

The traditional key building method cannot construct a search key from these predicates because a predicate on the first column a of the partitioning key is missing. As a result, the query execution plan composed by the DBMS must perform a full table scan.

Still another disadvantage inherent in the B-Tree index structure results when the search query includes an intervening IN predicate. For example, consider the predicates:

where a=10

and b in (20, 30)

and c=40

and d=50

The IN predicate on column b specifies an equality comparison with a set of values. The traditional key building method is capable of dealing with an equality comparison that involves exactly one value, but not a set of values. Consequently, the IN predicate cannot be used in the key. As a result, the search key contains only column a:

begin key: a=10

end key: a=10

The absence of a usable key predicate on column b prevents the predicates on columns c and d from being used. As a result, a complete search of columns b, c, d must be conducted.

Another disadvantage with existing B-Tree index-based DBMSs results from the mandatory use of the disjunctive normal form for the predicates of the query commands. More particularly, predicates are in disjunctive normal form when only ORs exist at the outer level. For example, consider the query command:

SELECT *

FROM T

WHERE (a=5 and ( (b=1 and c IN (2,4,9))

OR (b=8 and c=7))

OR (a between 4 and 6 and ( (b between 8 and 10 and c between 6 and 9)

OR (b=9 and c=11)

The disjuncts for this expression are:

(a=5 and b=1 and c IN (2,4,9))

OR (a=5 and b=8 and c=7)

OR (a>=4 and a<=6 and b>=8 and b<=10 and c>=6 and c<=9)

OR (a>=4 and a<=6 and b=9 and c=11)

In a typical known DBMS, the search for all records pertinent to the query command would begin with the first disjunct. Once all such records have been found, the search would be conducted for all records pertinent to the second disjunct, followed by a search for all records pertinent to the third disjunct, and ending with all records pertinent to the fourth disjunct. This technique is inefficient due to the fact that the single record in the second disjunct is accessed again during the search for records pertinent to the third disjunct. Although the above example requires only one repetitive reading of the same record, in practice relatively large numbers of repetitions occur routinely when accessing records in relatively large databases.

Further compounding the repetitive record problem is the fact that a record cannot be returned twice to a user during an access due to semantic constraints imposed by the system. Consequently, most DBMSs must create a table of records that have been read during an access, which can require a substantial amount of memory space, depending upon the number of records specified by the search query.

This problem of repetitive record accessing is sometimes exacerbated by the appearance of conflicting predicates in a query command. While a user rarely submits a query command with conflicting predicates, the problem can frequently arise when views with hidden predicates are used or when host variables are used in combination with fixed values, or when queries are generated by software. For example, assume the following view exists:

Create view VT as SELECT * from T where b IN (3, 9, 16, 25, 36);

Assume the user query is: SELECT * from VT

WHERE

b between 20 and 30

AND c IN (40, 100, 150)

AND d=50;

In this example, the user has unknowingly required the DBMS to search all values of b in the view lying in the range between 20 and 30, when there is only one value b in the view lying within this range. As a result, all values of b between 20 and 30 will be accessed, resulting in 30 unnecessary records (10 unnecessary b values times 3 c values).

SUMMARY OF THE INVENTION

The invention comprises a method and system for affording improved indexed accessing of records in a relational database management system which is capable of substantially reducing the total number of records accessed in a given search, which permits ranges and IN lists on multiple columns of a search key, which constructs a usable search key in the absence of one or more column values, and which orders the individual columns of the search key in the same manner as the table to which the key pertains.

The invention is carried out by means of a portion of a DBMS compiler termed the Optimizer and a DBMS Executor. The Optimizer is a process component of a DBMS compiler which initially evaluates a search query and generates key expressions for the DBMS Executor. The key expressions describe multi-column keys, including the range and IN list predicates on the individual columns. The Optimizer performs general OR optimization and associates query statement predicates with clusters and disjunct numbers. The use of disjunct numbers in the Optimizer allows the invention to minimize memory space usage for the predicates and disjuncts, since predicates are not repeated: rather, a list of disjunct numbers in which each predicate appears is created. Predicates may share a common set of disjunct numbers. IN lists are treated as a single disjunct to minimize the number of disjuncts.

The DBMS Executor comprises a set of procedures in the DBMS system library that executes compiled query statements against database tables, views or catalogs. The DBMS Executor evaluates the key expressions supplied by the Optimizer portion of the DBMS compiler in order to create a data structure termed a GEM-tree. Each GEM-tree contains information concerning key columns, describing ranges and exact values, predicates defined on each column, comparison operators and other information. The process of building the GEM-tree conducted in the DBMS Executor includes combining ranges and eliminating duplicates on the key columns, while preserving the order in each column (i.e., ascending order or descending order). After a GEM-tree has been constructed by the DBMS Executor, values are retrieved from the tree to build the actual keys for reading data from the required tables.

In the process of constructing the GEM-tree, the DBMS Executor sorts and collapses values from different disjuncts in a column together so that individual records are only read once. This results in a significant saving in the cost of executing a search plan, since all duplicate values are eliminated. Further, the keys are built in such a fashion that the data from each index is read in index order, even when multiple disjuncts are present, which facilitates the accessing of individual records.

The use of disjunct numbers in the DBMS Executor on a per column basis allows the collapse of multiple column disjuncts so that the same record never needs to be read twice. This facilitates the sorting and collapsing of values by the DBMS Executor.

The DBMS Executor also finds the minimum set of all predicates for a disjunct from all predicates for that column in a disjunct. This occurs when there are multiple predicates on a single column which conflict. The minimum set of all predicates is determined by finding the minimum set of values necessary for the combination of predicates. This technique, taken together with the sorting and collapsing of values from different disjuncts ensures that only the minimum amount of data need be read.

In the process of constructing the GEM-tree, the DBMS Executor recognizes missing keys and the specification of ranges and IN lists in the generalized key expressions supplied by the Optimizer portion of the DBMS compiler. This permits a multi-dimensional view of the index, and allows efficient access.

For a fuller understanding of the nature and advantages of the invention, reference should be had to the ensuing detailed description taken in conjunction with the accompanying drawings.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram of a computer system for storing and providing user access to data in stored databases;

FIG. 2 is a block diagram of data structures stored in a database management system;

FIG. 3 is a block diagram of the catalog data structure, representing database tables and programs, shown in FIG. 2; and

FIGS. 4A-4H are block diagrams representing portions of the tables included in the catalog data structure of FIG. 3.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS

Referring to FIG. 1, there is shown a computer system 100 for storing and providing user access to data in stored databases. The system 100 is a distributed computer system having multiple computers 102, 104, 106 interconnected by local area and wide area network communication media 108. The system 100 generally includes at least one database server 102 and many user workstation computers or terminals 104, 106.

When very large databases are stored in a system, the database tables will be partitioned, and different partitions of the database tables will often be stored in different physical disks controlled by different CPUs. However, from the viewpoint of user workstation computers 104, 106, the database server 102 appears to be a single entity. The partitioning of databases is well known to those skilled in the art.

As shown in FIG. 1, the database server 102 includes a central processing unit (CPU) 110, primary memory 112, a communications interface 114 for communicating with user workstations 104, 106 as well as other system resources not relevant here. Secondary memory 116, typically magnetic disc storage, in the database server 102 stores database tables 120, database indices 122, a database management system (DBMS) 123 for enabling user and operator access to the database tables, and one or more catalogs 126 for storing schema information about the database tables 120 as well as directory information for programs used to access the database tables. The DBMS 123 includes a SQL executor 124 as well as other database management subsystems, such as an SQL catalog manager 125 and an SQL command interpreter. The DBMS 123 further includes an SQL compiler 128 for compiling source code database query programs 130 into compiled execution plans 132. The SQL compiler 128 can also be used to compile any specified SQL statement so as to generate an execution plan.

End user workstations 104, 106, typically include a central processing unit (CPU) 140, primary memory 142, a communications interface 144 for communicating with the database server 102 and other system resources, secondary memory 146, and a user interface 148. The user interface 148 typically includes a keyboard and display device, and many include additional resources such as a pointing device and printer. Secondary memory 146 is used for storing computer programs, such as communications software used to access the database server 102. Some end user workstations 106 may be "dumb" terminals that do not include any secondary memory 146, and thus execute only software downloaded into primary memory 142 from a server computer, such as the database server 102 or a file server (not shown).

Glossary

To assist the reader, the following glossary of terms used in this document is provided.

SQL: SQL stands for "Structural Query Language." Most commercial database servers utilize SQL. Any program for accessing data in a database which utilizes SQL is herein called an "SQL Program." Each statement in an SQL program used to access data in a database is called an "SQL statement." An SQL program contains one or more SQL statements.

Execution Plan: An SQL statement which has been compiled into an intermediate form that specifies a method to efficiently access data in a database.

Execution Characteristics: Characteristics of an execution plan that have no effect on its semantics (i.e., operability). Examples are the performance of a plan, and its resource consumption.

Object(s): An object is a file, database table or other encapsulated computer resource accessed by a program as a unitary structure. In the context of the preferred embodiment, objects are database tables. In other implementations of the present invention, objects may be other encapsulated computer resources which the end user accesses indirectly through validated methods (i.e., programs) designated specifically to access those computer resources.

DDL Statement: A data definition language statement. DDL statements are used to create and modify database object (e.g., tables and indices).

DEFINE name: An object handle or link indicating an object to be accessed by an execution plan. An SQL statement may reference objects via a DEFINE names, instead of referencing them directly. This enables the operator to redirect the program to access a different set of objects than the compile-time objects, without having to alter the program, by merely altering the DEFINE names to point to new objects before executing the program.

Source Code Program/Statement: For each execution plan there is a corresponding source code SQL statement. A source code program is the set of SQL statements corresponding to a set of execution plans which together are herein called a "compiled program."

SQL compilation: The act of compiling an SQL statement program or an SQL program. The compilation can be a "static" compilation, performed by invoking an SQL compiler, such as Tandem's® SQLCOMP™, to generate new execution plans for SQL statements in the program. An SQL compilation can also be a dynamic compilation, such as an automatic recompilation initiated due to a program being marked invalid or due to timestamp mismatch between an SQL statement and an object referenced by the statement.

End user: A person using a workstation to access database information in a database server. End users typically do not have the authority to modify the structure of database tables.

Operator: A person using a workstation who has the authority and access rights to modify the structure of database tables and to manually initiate compilation of SQL source code programs.

View: A logical definition of a relation without physical existence. The data presented by a view is derived from a Base Table.

GEM: The acronym for general expression method, the term used to denote the several aspects of the invention.

MDAM: The acronym for multi-dimensional access method, an alternate term for the invention.

Database Server

FIG. 2 depicts some of the interrelationships between the data structures and programs stored in the database server 102.

A source code program 130-1 includes a sequence of SQL source code statements 160 as well as other non-SQL source code statements (e.g., assignments, and program flow control statements). SQL compiler 128 compiles the SQL source code statements into a compiled program 132-1 having a sequence of compiled statements 162 herein called execution plans. Each source code statements 160 has a corresponding execution plan 162. The compiled 132 program 132 includes a "file label" 164 (i.e., a data structure in the program) that stores a set of runtime properties used by the SQL executor 124, as will be discussed in more detail below. In addition, each execution plan 162 includes, in addition to the compiled query, a timestamp 166 and a set of schema information 170 for each of the database objects to be accessed by that execution plan.

Each database table or object 120 includes a "disk label" 180, herein called an object header, and an object body 182. The object header 180 stores information about the structure, identity and other characteristics of the database object 120, while the object body stores the data content of the database object. The object header 180 includes an object name field 184 and an object schema 186 defining the structure and other characteristics of the data in the database object. The object schema 186 stored in the database object's "disk label" 180 is a compact representation of the catalog information stored for the database table in the SQL catalog 126 and thus includes data attribute definitions 188, timestamps 190 and other object parameters 192.

The catalog 126 is itself a database having a set of tables for storing information about the database objects (e.g., tables and indices) stored in the database server as well as information about the programs stored in the database server. The structure of the catalog 126 will be described in more detail with reference to FIGS. 3 and 4A through 4H.

The compiler 128, as mentioned above, compiles an SQL program 130 into a compiled SQL program 132 having a set of execution plans 162. Operation of the compiler is initiated by either a manually entered compiler command 194 or a recompile command 196 generated by the SQL executor 124 when it attempts to execute an invalid or inoperable execution plan. Manually initiated compilations are governed by user or operator entered commands 194 or, more commonly, user or operator initiated scripts that contain sequences of data definition and compiler commands.

The SQL executor 124 responds to both end user and operator runtime commands 198. Such runtime commands include standard end user initiated plan execution commands, such as to retrieve data from database tables and to add data to database tables. Runtime commands 198 also include DDL statements, for creating database tables and for modifying the structure of existing database tables, although the authority to use these runtime commands 198 is usually restricted to a set of persons herein called operators. For a fuller description of the FIG. 1 system operation, reference may be made to "TANDEM SYSTEMS REVIEW", Vol. 4, No. 2 Jul., 1988, the disclosure of which is hereby incorporated by reference.

Catalog and Disk Label Data Structures

Referring to FIG. 3, the catalog 126 in the preferred embodiment, consists of a set of tables 200-220 representing database tables and programs in a database server or set of database servers.

Referring to FIG. 4A, the "Tables" table 200 includes one record 222 for each database table in the database server. Each record 222 includes the following fields:

TableName 224, denoting the name of the database table;

TableType 225, indicating whether the referenced database table is a true database table or a "view," which is a subset of one or more database tables that are referenced in the same manner as a database table by SQL statements;

ColumnCount 226, indicating the number of distinct columns in the table (or view);

CreateTime 227, is a timestamp value indicating when the table (or view) was first created;

RedefTime 228, is a timestamp value indicating when the table (or view) was last altered;

SimilarityCheck 229, is a flag whose value is Enabled when similarity checks on the table are allowed and is Disabled otherwise; and other parameters 230 not relevant here.

Referring to FIG. 4B, the "Base Tables" table 202 includes one record 232 for each database table in the database server. Each record 232 includes the following fields:

TableName 234 denoting the name of the database table;

FileName 235, indicting the name of the disk file in which the referenced database table is stored;

RowCount 236, indicating the number of rows in the table;

RowSize 237, indicating the maximum size (in bytes or words) of each row;

ValidDef 238, is a flag (Y or N) value indicating if the file has a valid definition, correct file label and catalog entries;

ValidDef 239, is a flag (Y or N) value indicating if the data in the table is consistent with data in the table's indexes and satisfies constraints on the table;

Constraints 240, is a flat (Y or N) value indicating whether the table has any defined constraints; and other parameters 241 not relevant here.

Referring to FIG. 4C, the "Columns" table 204 includes one record 252 for each column of each database table in the database server. Each record 252, representing characteristics of one database table column, includes the following fields:

TableName 254, denoting the name of the database table in which the column corresponding to this record 252 resides;

ColumnNumber 255, denotes a number indicating the position of the column in each row of the table, where the first column has a Column/Number of 0;

ColumnName 256, denotes the column's name, also called the SQL identifier, for the column;

ColumnSize 257, indicating the size (in bytes or words) of the data in the column;

UniqueEntryCount 258, denotes the number of unique data entries in the column for the table or table partition;

HeadingText 259, denotes a text string used as a default column heading when printing data extracted from this the column of the database table; and other parameters 260 not relevant here.

Referring to FIG. 4D, the indexes table 210 includes one record 262 for each database index in the database server. Each record 262 includes the following fields:

TableName 263 denoting the name of the database table;

IndexName 264, indicating the name of the index;

ColCount 265, indicating the number of columns used in the index, including the primary key columns;

Keytag 266, specifying the keytag, if this is a primary key index for the database table;

ValidDef 267, is a flag (Y or N) value indicating if the index definition is valid;

ValidData 268, is a flag (Y or N) value indicating if the index has valid data;

UniqueValue 269, is a flag (Y or N) value indicating whether all entries in the index are unique;

IndexLevels 270, indicating the number of levels of indexing in this index;

RowSize 271, indicating the size of each index record;

FileName 272, indicating the file that contains the index; and other parameters 273 not relevant here.

Referring to FIG. 4E, the Keys table 212 includes one record 282 for each column of the primary key and each other index for each database table in the database server. Each record 282, representing one table column for one key or index, includes the following fields:

IndexName 283, denoting the name of the index;

KeySequenceNumber 284, indicates the position of the column in each index row;

TableColumnNumber 285, indicates the position of the column in each table row; and

Ordering 286, indicates whether the column is an ascending order or descending order column.

Referring to FIG. 4F, the Files table 206 includes one record 292 for each database table and index in the database server. Each record 292, representing characteristics of one database file, includes the following fields;

FileName 294, denoting the name of a database file, and corresponds to the FileName entry 235 in a Base Tables record 232 or an entry 272 in an index record 262;

FileType 295, indicates how data within the file is sequenced (e.g., entry sequenced, key sequenced, etc.);

BlockSize 296, denotes the size of the secondary memory blocks (e.g., 512, 1024, 2048 or 4096 bytes) in which the file is stored;

Partitioned 297, is a flag (Y or N) indicating whether or not the file is partitioned;

RecordSize 298, denotes the maximum length of a record in the file;

CompressionInfo 299, is a flag (Y or N) value indicating whether data in the data pages and index pages of the file have been compressed;

ExtentsInfo 300, denotes the size of the primary and secondary extents and the maximum number of extents in the file; and other parameters 301 not relevant here.

When a file is partitioned, the Partitions table 214 will contain one record for each partition of the file indicating the partition name and catalog entry for each partition as well as the starting values for each column in the file's primary key.

Referring to FIG. 4G, the Programs table 208 includes one record 312 for each registered program in the database server. Each record 312, representing characteristics of one program, includes the following fields:

ProgramName 314, denoting the name of a program;.

OwnerID 315, identifies the program's owner;

CreateTime 316, is a timestamp value indicating when the program was first SQL compiled;

RecompileTime 317, is a timestamp value indicating when the program was last recompiled;

Valid 318, is a flag (Y or N) value indicating whether or not the program is valid;

AutoCompile 319, is a flag (Y or N) value indicating whether automatic recompilations of the program are allowed at run time, if required;

RecompileMode 320, is a mode value that is set to "All" or "OnDemand" and governs (in conjunction with the AutoCompile and CheckMode parameters) when program and statements within the program are recompiled, as explained in more detail below;

CheckMode 321, is a mode value that is set to "InvalidProgram," "InvalidPlans," or "InoperablePlans," and governs (in conjunction with the AutoCompile and REcompileMode parameters) when the program and statements within the program are recompiled;

SimilarityInfo 322, is a flag (Y or N) value indicating whether the compiled program includes similarity information for each of the program's compiled statements, where the similarity information for each statement consists of a subset of the schemas for database tables accessed by that statement; and other parameters 323 not relevant here.

Referring to FIG. 4H,, the Usages table 220 includes one record 330 for each usage of one object by another. For each program that uses a database table there is a record 330, representing that relationship that includes the following fields:

UsedObjectName 332, identifies the name of the "used" object, which in the context of this document is the tablename of a database table;

UsedObjectType 334, identifies the type of the used object, which in this case is "table"; other defined object types for used objects are "view" and "index";

RelationshipType 336, is flag that is enabled if the using object depends on the used object;

UsingObjectName 337, identifies the name of the "using" object, which in the context of this document is the name of a program;

UsingObjectType 338, identifies the type of the using object, which in this case is "program"; other defined object types for using objects are "view" and "index"; and other parameters 339 not relevant here.

The principal components of the computer system of FIG. 1 used to implement the invention are a portion of the SQL Compiler 128 termed the Optimizer and the SQL Executor 124. The Optimizer is a process component of SQL Compiler 128 which initially evaluates a search query and generates key expressions for the SQL Executor 124. The key expressions describe multi-column keys, including the range and IN list predicates on the individual columns. The Optimizer conducts general OR optimization and associates predicates with clusters and disjunct numbers in the manner set forth in Appendix A. The use of disjunct numbers in the Optimizer allows the invention to minimize memory space usage for the predicates and disjuncts. More particularly, in prior art compilers the process of converting a search query to disjunctive normal form requires that the predicates be repeated for all the disjuncts in which they appear. In the invention, predicates are not repeated: rather, a list of disjuncts in which each predicate appears is created in the manner set forth in Appendix A. In addition, many predicates share a common set of disjunct numbers. Another advantage of the invention resides in the treatment of IN lists as a single disjunct in order to minimize the number of disjuncts. An IN list is a shorthand way of specifying a list of single predicates on the same column that are ORed together. This list of same column predicates ORed together is treated as a single disjunct.

The SQL Executor 124 comprises a set of procedures in the system library that executes compiled SQL statements against database tables, views or the database catalogs. The SQL Executor 124 evaluates key expressions supplied by the Optimizer portion of SQL Compiler 128 in order to create a data structure termed a GEM-tree. Each GEM-tree contains information concerning key columns, describing ranges and exact values, predicates defined on each column, comparison operators and other information. The process of building the GEM-tree conducted in the SQL Executor 124 includes combining ranges and eliminating duplicates on the key columns, while preserving the order in each column (i.e., ascending order or descending order). After a GEM-tree has been constructed by the SQL Executor 124, values are retrieved from the tree to build the actual keys for reading data from the required tables. The specific manner in which the SQL Executor 124 constructs a GEM-tree and builds the actual keys for reading data from the tables is set forth in Appendix B.

In the process of constructing the GEM-tree, the SQL Executor 124 sorts and collapses values from different disjuncts in a column together so that individual records are only read once. This is a significant saving in the cost of executing a search plan, since all duplicate values are eliminated. In addition, the keys are built in such a fashion that the data from each index is read in index order, even when multiple disjuncts are present, which facilitates the accessing of individual records.

The use of disjunct numbers in the SQL Executor 124 on a per column basis allows the collapse of multiple column disjuncts so that the same record never needs to be read twice. This facilitates the sorting and collapsing of values by the SQL Executor 124.

The SQL Executor 124 also finds the minimum set of all predicates for a disjunct from all predicates for that column in a disjunct. This occurs when there are multiple predicates on a single column which conflict. The SQL Executor 124 finds the minimum set of all predicates by finding the minimum set of values necessary for the combination of predicates, which avoids unnecessary reading of data. Taken together with the sorting and collapsing of values from different disjuncts, this ensures that only the minimum amount of data need be read.

In the process of constructing the GEM-tree, the SQL Executor 124 recognizes missing keys and the specification of ranges and IN lists in the generalized key expressions supplied by the Optimizer portion of SQL Compiler 128. This permits a multi-dimensional view of the index, and allows efficient access even if the user has defined a column to the beginning of an index for purely partitioning purposes.

Specific examples of the features noted above are as follows.

Intervening Range

Assume the user search query includes the following predicates:

WHERE a=10

AND b between 20 and 30

AND c=40

AND d=50;

In prior art systems, the predicates in column c and d cannot be used as keys because of the intervening range predicate on b. The invention allows the use of all four key columns in the following fashion.

Range predicates are processed in the SQL Executor 124 by stepping through the values of the column in the range. Assume the values of b between 20 and 30 are (20, 23, 25, 30). The SQL Executor 124 first performs a keyed access for

    a=10, b=20, c=40, d=50

After all the records for these key columns have been received by the SQL Executor 124, it requests from the file system the next value of b, which is 23. The value 23 is then substituted as the key value for b:

    a=10, b=23; c=40, d=50

After these records are retrieved, the next value of b is selected (i.e., the value 25).

Missing Key Predicate

Assume the user search query includes the following predicates:

WHERE

b between 20 and 30

AND c=40

AND d=50;

Since the predicate for key column a is missing (i.e., unspecified), prior art systems cannot use this index for keyed access. According to the invention, however, the missing predicate for column a is treated as an implied range of MIN₋₋ VALUE to MAX₋₋ VALUE (including NULL values). The SQL Executor 124 first requests the first value from column a from the file system, and substitutes that value in the begin key values.

Assume the values for a include all values from 1 to 100. The SQL Executor 124 first performs a keyed access with the following values:

    a=1, b=20, c=40, d=50

After retrieving the records for this set of values, SQL Executor 124 varies b through its four values:

    a=1, b=23, c=40, d=50

    a=1, b=25, c=40, d=50

    a=1, b=30, c=40, d=50

SQL Executor 124 then obtains the next value of a from the file system and repeats the values for b:

    a=2, b=20, c=40, d=50

    a=2, b=23, c=40, d=50

etc.

The result is a total of 400 accesses.

IN Lists

Assume the user search query includes the predicates:

WHERE

b between 20 and 30

AND c IN (40, 100, 150)

AND D=50;

Columns a and b are treated in the same fashion as in the missing key predicate example given above. In addition, the values of c are included. The SQL Executor 124 steps through all the given values for a, b and c. However, since the three values of c are specified by the IN list, the SQL Executor 124 can use these values directly (and need not request these values from the file system).

Elimination of Conflicting Predicates

Assume that the following view exists:

Create view VT as

SELECT * from T where b IN (3, 9, 16, 25, 36);

Assume the user query is:

SELECT * from VT

WHERE

b between 20 and 30

AND c IN (40, 100, 150)

AND d=50;

The only valid value for b in this query is 25. The SQL Executor 124 finds the union of all the predicates for b, and recognizes that only the value 25 exists in both sets, so only that value for b will be used to retrieve records.

General OR Optimization

As noted above, general OR optimization is accomplished by associating the predicates with different predicate sets in disjunctive normal form (with the exception of IN lists which are processed as a unit). Predicates are in disjunctive normal form when only ORs exists at the outer level. For example, consider the query command:

SELECT *

FROM T

WHERE (a=5 and ((b=1 and c IN (2,4,9))

OR (b=8 and c=7))

OR (a between 4 and 6 and ((b between 8 and 10 and c between 6 and 9)

OR (b=9 and c=11)

The disjuncts for this expression are:

(a=5 and b=1 and c IN (2,4,9))

OR (a=5 and b=8 and c=7)

OR (a>=4 and a<=6 and b>=8 and b<=10 and c>=6 and c<=9)

OR (a>=4 and a<=6 and b=9 and c=11)

The SQL Executor 124 eliminates any conflicting predicates within each disjunct, and then combines the overlaps among the disjuncts so that only the minimum set of records is retrieved, and in the order of the index. For this example, the following retrievals are made:

a=4, b=8, c>=6 and c<=9

a=4, b=9, c>=6 and c<=9

a=4, b=9, c=11

a=4, b=10, c>=6 and c<=9

a=5, b=1, c=2

a=5, b=1, c=4

a=5, b=9, c=11

a=5, b=8, c>=6 and c<=9

a=5, b=9, c>=6 and c<=9

a=5, b=9, c=11

a=5, b=10, c>=6 and c<=9

a=6, b=8, c>=6 and c<=9

a=6, b=9, c>=6 and c<=9

a=6, b=9, c=11

a=6, b=10, c>=6 and c<=9

As will now be apparent, the invention affords several advantages over known B-Tree indexed access techniques. Firstly, by associating predicates with clusters and clusters with disjunct numbers, the invention permits the use of highly complex user search queries, and is thus not restricted to queries in which the predicates are already expressed in disjunctive normal form. In addition, the use of these associative techniques saves substantial space in memory by eliminating the need to store several copies of the same predicate. Further, the user can specify both ranges and IN lists in multiple key columns, and these ranges and IN lists will be observed in building the keys. Likewise, a missing key predicate, whether intentionally or inadvertently omitted, does not prevent the construction of a usable key index. Moreover, by sorting and collapsing values from different disjuncts and finding the minimum set of all predicates for a disjunct, repetitive reads of the same record are eliminated from the search key (which eliminates the need to construct a table of records that have been read) and only the minimum amount of data will be read in the proper order.

While the above provides a full and complete disclosure of the preferred embodiments of the invention, various modifications, alternate constructions and equivalents will appear to those skilled in the art. For example, although the invention has been described with reference to a DBMS employing SQL, other query languages may be employed, as desired. Therefore, the above descriptions and illustrations should not be construed as limiting the invention, which is defined by the appended claims. ##SPC1## 

What is claimed is:
 1. A method of constructing search keys for searching a multi-column table in a database using search keys constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said method comprising the steps of:(a) evaluating the predicate values corresponding to the values of the preselected columns of the table specified by the search query; (b) for each predicate value specified as a range of values, assigning equivalent range values to the corresponding preselected column; (c) for each predicate value specified as an IN list of values, assigning equivalent values to the corresponding preselected column; (d) for each unspecified predicate value, assigning a range of values to the corresponding preselected column; and (e) using the assigned equivalent values from steps (b)-(d) to construct individual search keys for searching the table; wherein a search query includes a plurality of disjuncts; and wherein said step (a) of evaluating includes the step of assigning a unique disjunct number to each of said plurality of disjuncts.
 2. The method of claim 1 wherein said step of assigning disjunct numbers includes the step of assigning an individual disjunct number to an IN list predicate.
 3. The method of claim 1 wherein said step (a) of evaluating includes the steps of associating predicates to clusters and associating clusters to disjunct numbers.
 4. A method of constructing search keys for searching a multi-column table in a database using search keys constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said method comprising the steps of:(a) evaluating the predicate values corresponding to the values of the preselected columns of the table specified by the search query; (b) for each predicate value specified as a range of values, assigning equivalent range values to the corresponding preselected column; (c) for each predicate value specified as an IN list of values, assigning equivalent values to the corresponding preselected column; (d) for each unspecified predicate value, assigning a range of values to the corresponding preselected column; and (e) using the assigned equivalent values from steps (b)-(d) to construct individual search keys for searching the table; wherein said equivalent range values assigned in step (b) are specified as the lo and hi values of the corresponding preselected column.
 5. A method of constructing search keys for searching a multi-column table in a database using search keys constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said method comprising the steps of:(a) evaluating the predicate values corresponding to the values of the preselected columns of the table specified by the search query; (b) for each predicate value specified as a range of values, assigning equivalent range values to the corresponding preselected column; (c) for each predicate value specified as an IN list of values, assigning equivalent values to the corresponding preselected column; (d) for each unspecified predicate value, assigning a range of values to the corresponding preselected column; and (e) using the assigned equivalent values from steps (b)-(d) to construct individual search keys for searching the table; wherein said step (e) of using includes the step of eliminating conflicting predicate values from the same column to reduce the number of potential predicate values for searching that column.
 6. A method of constructing search keys for searching a multi-column table in a database using search keys constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said method comprising the steps of:(a) evaluating the predicate values corresponding to the values of the preselected columns of the table specified by the search query; (b) for each predicate value specified as a range of values, assigning equivalent range values to the corresponding preselected column; (c) for each predicate value specified as an IN list of values, assigning equivalent values to the corresponding preselected column; (d) for each unspecified predicate value, assigning a range of values to the corresponding preselected column; and (e) using the assigned equivalent values from steps (b)-(d) to construct individual search keys for searching the table; wherein said step (e) of using includes the step of eliminating redundant values specified by the disjuncts to minimize the number of search keys required to fulfill the search query.
 7. A computer system for storing and providing user access to data in stored database objects, said system comprising:a memory for storing said database objects; a communications interface through which user database queries are relayed to said computer system from a user workstation, and through which query results from said computer system are made available to the user workstation; a processor for controlling interactions between said memory and said communications interface in response to a search query received from a user workstation and specifying predicate values corresponding to values of preselected columns of a multi-column table; a computer program for causing said processor to construct individual search keys in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said computer program including a first procedure for evaluating the predicate values specified by the search query; a second procedure for assigning equivalent range values for each predicate value specified in the search query as a range of values, to the corresponding preselected column; a third procedure for assigning equivalent values for each predicate value specified in the search query as an IN list of values, to the corresponding preselected column; a fourth procedure for assigning a range of values to the corresponding preselected column for each unspecified predicate value; and a fifth procedure for constructing individual search keys from the equivalent values assigned by the first through fourth procedures; wherein a search query includes a plurality of disjuncts; and wherein said first procedure causes said processor to assign a unique disjunct number to each of the plurality of disjuncts in the search query.
 8. The system of claim 7 wherein the first procedure causes said processor to assign an individual disjunct number to an IN list predicate.
 9. The system of claim 7 wherein the first procedure causes said processor to associate predicates to clusters and associate clusters to disjunct numbers.
 10. A computer system for storing and providing user access to data in stored database objects, said system comprising:a memory for storing said database objects; a communications interface through which user database queries are relayed to said computer system from a user workstation, and through which query results from said computer system are made available to the user workstation; a processor for controlling interactions between said memory and said communications interface in response to a search query received from a user workstation and specifying predicate values corresponding to values of preselected columns of a multi-column table; a computer program for causing said processor to construct individual search keys in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said computer program including a first procedure for evaluating the predicate values specified by the search query; a second procedure for assigning equivalent range values for each predicate value specified in the search query as a range of values, to the corresponding preselected column; a third procedure for assigning equivalent values for each predicate value specified in the search query as an IN list of values, to the corresponding preselected column; a fourth procedure for assigning a range of values to the corresponding preselected column for each unspecified predicate value; and a fifth procedure for constructing individual search keys from the equivalent values assigned by the first through fourth procedures; wherein the equivalent range values assigned by the processor in response to the second procedure are specified as the lo and hi values of the corresponding predicate column.
 11. A computer system for storing and providing user access to data in stored database objects, said system comprising:a memory for storing said database objects; a communications interface through which user database queries are relayed to said computer system from a user workstation, and through which query results from said computer system are made available to the user workstation; a processor for controlling interactions between said memory and said communications interface in response to a search query received from a user workstation and specifying predicate values corresponding to values of preselected columns of a multi-column table; a computer program for causing said processor to construct individual search keys in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said computer program including a first procedure for evaluating the predicate values specified by the search query; a second procedure for assigning equivalent range values for each predicate value specified in the search query as a range of values, to the corresponding preselected column; a third procedure for assigning equivalent values for each predicate value specified in the search query as an IN list of values, to the corresponding preselected column; a fourth procedure for assigning a range of values to the corresponding preselected column for each unspecified predicate value; and a fifth procedure for constructing individual search keys from the equivalent values assigned by the first through fourth procedures; wherein the fifth procedure causes said processor to eliminate conflicting predicate values from the same column to reduce the number of potential predicate values for searching that column.
 12. A computer system for storing and providing user access to data in stored database objects, said system comprising:a memory for storing said database objects; a communications interface through which user database queries are relayed to said computer system from a user workstation, and through which query results from said computer system are made available to the user workstation; a processor for controlling interactions between said memory and said communications interface in response to a search query received from a user workstation and specifying predicate values corresponding to values of preselected columns of a multi-column table; a computer program for causing said processor to construct individual search keys in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, said computer program including a first procedure for evaluating the predicate values specified by the search query; a second procedure for assigning equivalent range values for each predicate value specified in the search query as a range of values, to the corresponding preselected column; a third procedure for assigning equivalent values for each predicate value specified in the search query as an IN list of values, to the corresponding preselected column; a fourth procedure for assigning a range of values to the corresponding preselected column for each unspecified predicate value; and a fifth procedure for constructing individual search keys from the equivalent values assigned by the first through fourth procedures; The system of claim 8 wherein the fifth procedure causes said processor to eliminate redundant values specified by the disjuncts in order to minimize the number of search keys required to fulfill the search query.
 13. A computer program product comprising a computer usable medium having computer readable code embodied therein for constructing individual search keys for searching a multi-column table in a database, the search keys being constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, the computer program product comprising:first computer readable program code devices configured to cause a computer to evaluate the predicate values specified by the search query and corresponding to the values of the preselected columns of the table; second computer readable program code devices configured to cause a computer to assign, for each predicate value specified as a range of values, equivalent range values to the corresponding preselected column; third computer readable program code devices configured to cause a computer to assign, for each predicate value specified as an IN list of values, equivalent values to the corresponding preselected column; fourth computer readable program code devices configured to cause a computer to assign, for each unspecified predicate value, a range of values to the corresponding preselected column; and fifth computer readable program code devices configured to cause a computer to use said equivalent values to construct individual search keys; wherein a search query includes a plurality of disjuncts; and wherein said first computer readable program code devices are configured to cause a computer to assign a unique disjunct number to each of said plurality of disjuncts.
 14. The computer program product of claim 13 wherein the computer is caused to assign an individual disjunct number to an IN list predicate.
 15. The computer program product of claim 13 wherein said first computer readable program code devices are configured to cause the computer to associate predicates to clusters and clusters to disjunct numbers.
 16. A computer program product comprising a computer usable medium having computer readable code embodied therein for constructing individual search keys for searching a multi-column table in a database, the search keys being constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, the computer program product comprising:first computer readable program code devices configured to cause a computer to evaluate the predicate values specified by the search query and corresponding to the values of the preselected columns of the table; second computer readable program code devices configured to cause a computer to assign, for each predicate value specified as a range of values, equivalent range values to the corresponding preselected column; third computer readable program code devices configured to cause a computer to assign, for each predicate value specified as an IN list of values, equivalent values to the corresponding preselected column; fourth computer readable program code devices configured to cause a computer to assign, for each unspecified predicate value, a range of values to the corresponding preselected column; and fifth computer readable program code devices configured to cause a computer to use said equivalent values to construct individual search keys; wherein the equivalent range values assigned by the computer in response to said second computer readable program code devices are specified as the lo and hi values of the corresponding predicate column.
 17. A computer program product comprising a computer usable medium having computer readable code embodied therein for constructing individual search keys for searching a multi-column table in a database, the search keys being constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, the computer program product comprising:first computer readable program code devices configured to cause a computer to evaluate the predicate values specified by the search query and corresponding to the values of the preselected columns of the table; second computer readable program code devices configured to cause a computer to assign, for each predicate value specified as a range of values, equivalent range values to the corresponding preselected column; third computer readable program code devices configured to cause a computer to assign, for each predicate value specified as an IN list of values, equivalent values to the corresponding preselected column; fourth computer readable program code devices configured to cause a computer to assign, for each unspecified predicate value, a range of values to the corresponding preselected column; and fifth computer readable program code devices configured to cause a computer to use said equivalent values to construct individual search keys; wherein the fifth computer readable program code devices are additionally configured to cause the computer to eliminate conflicting predicate values from the same column to reduce the number of potential predicate values for searching that column.
 18. A computer program product comprising a computer usable medium having computer readable code embodied therein for constructing individual search keys for searching a multi-column table in a database, the search keys being constructed in accordance with a search query specifying predicate values corresponding to values of preselected columns of the table, the search keys including names of the preselected columns of the table and associated predicate values, the computer program product comprising:first computer readable program code devices configured to cause a computer to evaluate the predicate values specified by the search query and corresponding to the values of the preselected columns of the table; second computer readable program code devices configured to cause a computer to assign, for each predicate value specified as a range of values, equivalent range values to the corresponding preselected column; third computer readable program code devices configured to cause a computer to assign, for each predicate value specified as an IN list of values, equivalent values to the corresponding preselected column; fourth computer readable program code devices configured to cause a computer to assign, for each unspecified predicate value, a range of values to the corresponding preselected column; and fifth computer readable program code devices configured to cause a computer to use said equivalent values to construct individual search keys; wherein said fifth computer readable program code devices are additionally configured to cause the computer to eliminate redundant values specified by the disjuncts to minimize the number of search keys required to fulfill the search query. 